//
//  ThorBaseRequestSerivce.m
//  ThorWebView_Example
//
//  Created by panfei mao on 2019/1/15.
//  Copyright © 2019 panfei mao. All rights reserved.
//

#import "ThorBaseRequestSerivce.h"

@implementation ThorBaseRequestSerivce

- (YTKRequestMethod)requestMethod{
    return YTKRequestMethodPOST;
}

//  设置json数据格式请求
- (YTKRequestSerializerType)requestSerializerType{
    return YTKRequestSerializerTypeJSON;
}

//  设置请求header
- (NSDictionary<NSString *,NSString *> *)requestHeaderFieldValueDictionary{
    return [ThorBaseRequestSerivce baseDictionaryWithBaseParameters:self.requestArgument method:[self requestUrl]];
}

//  设置header基础参数
+ (NSDictionary *)baseDictionaryWithBaseParameters:(NSDictionary *)paramDict method:(NSString *)method{
    return @{};
}

//  发起网络请求
- (void)requestWithSuccess:(successBlock)success failure:(failureBlock)failure{
    [self startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSDictionary *responseDict = request.responseJSONObject;
        NSDictionary *dataDict = responseDict[@"data"];
        if (![dataDict isKindOfClass:[NSDictionary class]]) {
            dataDict = nil;
        }
        success(responseDict);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        failure(request);
    }];
}

@end
